import time
from timeit import timeit

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome(executable_path='Chromedriver.exe')
driver.get("http://121.43.169.97:8848/pageA.html")
'''
# 1. 导包 Select类 --> from selenium.webdriver.support.select import Select
# 2. 实例化Select类
# 匿名：Select(element).select_by_index() #下拉/索引
# 实名：select = Select(element)
#      select_by_index()


# 注意
# 1. Select类是通过select标签控制其下的option元素
# 2. element：只能是select标签
'''
# --------------------------------下标/索引 实现---------------------
'''
# 1.选择广州
el = driver.find_element_by_css_selector("#selectA")
select = Select(el)
time.sleep(2)
select.select_by_index(2)

# 暂停两秒，选择上海

time.sleep(2)
select.select_by_index(1)

# 暂停两秒，选择北京

time.sleep(2)
select.select_by_index(0)
'''


'''
# --------------------------------value值实现---------------------
# 1.选择广州
el = driver.find_element_by_css_selector("#selectA")
select = Select(el)
time.sleep(2)
select.select_by_index("gz")

# 暂停两秒，选择上海

time.sleep(2)
select.select_by_index("sh")

# 暂停两秒，选择北京

time.sleep(2)
select.select_by_index("bj")
'''


# --------------------------------文本值显示内容---------------------
# 1.选择广州
el = driver.find_element_by_css_selector("#selectA")
select = Select(el)
time.sleep(2)
select.select_by_visible_text("广州")

# 暂停两秒，选择上海

time.sleep(2)
select.select_by_visible_text("上海")

# 暂停两秒，选择北京

time.sleep(2)
select.select_by_visible_text("北京")
